package com.jack.MainXiangDuiXiang;

public class MianXiangDuiXiang_01 {
    public String name;
    public int age;
    public char sex;
    public static float height;
    //创建实例代码块
    {
        System.out.println("正在执行实例代码块!");
    }
    //创建静态代码块
    static {
        System.out.println("正在执行静态代码块!");
    }
    //创建无参构造器
    MianXiangDuiXiang_01(){

    }
    //创建有参构造器
    MianXiangDuiXiang_01(String name,int age,char sex){
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
    //创建实例方法
    public void play(MianXiangDuiXiang_01 p){
        System.out.println("name:"+p.name+"  age:"+p.age+"  sex:"+p.sex+"  height:"+MianXiangDuiXiang_01.height);
    }
    //创建静态方法
    public static void work(){

        System.out.println("正在调用静态方法!");
    }

    //创建程序入口方法main方法
    public static void main(String[] args) {
        //给类成员变量赋值
        MianXiangDuiXiang_01.height = 168.4f;
        //通过无参构造器创建对象
        MianXiangDuiXiang_01 p1 = new MianXiangDuiXiang_01();
        //给实例p1的变量赋值
        p1.name = "jack";
        p1.age = 25;
        p1.sex = '男';
        //调用实例方法play()
        p1.play(p1);
        //调用静态方法work
        MianXiangDuiXiang_01.work();
        //使用有参构造器创建对象p2
        MianXiangDuiXiang_01 p2 = new MianXiangDuiXiang_01("rose",20,'女');
        MianXiangDuiXiang_01.height = 160.2f;
        //调用实例方法play()
        p2.play(p2);
        p1.play(p1);
        MianXiangDuiXiang_02 p3 = new MianXiangDuiXiang_02();
        p3.setName("张三");
        String name = p3.getName();
        System.out.println("name:"+name);
    }
}
